<template>
    <div>
        <Table border :columns="columns" :data="tableData">
            <template slot-scope="{ row }" slot="action">
                <div class="action-button">
                    <Button v-if="row.type==='0'" type="primary" size="small"  @click="goEdit(row.id)">编辑</Button>
                    <Button v-if="row.type==='0'" type="error" size="small" @click="deleteDataModal(row.id)">删除</Button>
                    <Button type="success" size="small" @click="goDetail(row.id)">详情</Button>
                </div>
            </template>
        </Table>
        <Page :total="pageInfo.total" :current="pageInfo.pageNo" @on-change="changePage" />
        <Modal v-model="deleteModal" title="确认操作" width="20" @on-ok="deleteData" >
            <div style="text-align:center">  <p>是否确认删除!</p>  </div>
        </Modal>

    </div>
</template>
<script>
import { findPageList, deleteForm } from '@/api/outbreak-management/government-Informationization-project/marketization-project'
// 街道疫情
export default {
  data () {
    return {
      // 弹出框
      deleteModal: false,
      // 删除 id
      currentDelId: '',
      // 表格
      columns: [
        // {
        //   title: '上报日期',
        //   key: 'sbrq',
        //   minWidth: 120
        // },
        {
          title: '项目名称',
          minWidth: 120,
          key: 'xmmc'
        }, {
          title: '项目单位名称',
          minWidth: 130,
          key: 'xmdwmc'
          // render: (h, params) => {
          //   let dwmc = ''
          //   if (params.row.xmdwmc)dwmc = JSON.parse(params.row.xmdwmc)
          //   dwmc = dwmc && Array.isArray(dwmc) ? dwmc.join('/') : ''
          //   return h('div', [
          //     h('Tooltip', {
          //       props: { placement: 'top', transfer: true }
          //     }, [
          //       h('span', {
          //         style: {
          //           display: 'inline-block',
          //           width: params.column._width * 0.9 + 'px',
          //           overflow: 'hidden',
          //           textOverflow: 'ellipsis',
          //           whiteSpace: 'nowrap'
          //         }
          //       }, dwmc),
          //       h('span', {
          //         slot: 'content',
          //         style: { whiteSpace: 'normal', wordBreak: 'break-all' }
          //       }, dwmc)
          //     ])
          //   ])
          // }
        },
        {
          title: '市场化主体单位',
          minWidth: 140,
          key: 'schztdw'
          // render: (h, params) => {
          //   let dwmc = ''
          //   if (params.row.schztdw) dwmc = JSON.parse(params.row.schztdw)
          //   dwmc = dwmc && Array.isArray(dwmc) ? dwmc.join('/') : ''
          //   return h('div', [
          //     h('Tooltip', {
          //       props: { placement: 'top', transfer: true }
          //     }, [
          //       h('span', {
          //         style: {
          //           display: 'inline-block',
          //           width: params.column._width * 0.9 + 'px',
          //           overflow: 'hidden',
          //           textOverflow: 'ellipsis',
          //           whiteSpace: 'nowrap'
          //         }
          //       }, dwmc),
          //       h('span', {
          //         slot: 'content',
          //         style: { whiteSpace: 'normal', wordBreak: 'break-all' }
          //       }, dwmc)
          //     ])
          //   ])
          // }
        }, {
          title: '市场化参与建设情况概述',
          minWidth: 200,
          key: 'schjsms'
        }, {
          title: '项目概述',
          minWidth: 120,
          key: 'xmgs'
        },
        {
          title: '是否招标',
          minWidth: 100,
          key: 'sfzb'
        },
        {
          title: '填报单位',
          minWidth: 80,
          key: 'company_name'
        },
        {
          title: '审核状态',
          minWidth: 120,
          key: 'dept_audit_status',
          render: (h, params) => {
            let date = '未知状态'
            if (params.row.type === '0') {
              date = '未提报'
            } else if (params.row.type === '1') {
              date = '部门已审核'
            }
            return h('div', date)
          }
        },
        {
          title: '操作',
          slot: 'action',
          fixed: 'right',
          width: 180,
          align: 'center'
        }
      ],
      tableData: [],
      pageInfo: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  mounted () {
    this.changePage(this.pageInfo.pageNo)
  },
  methods: {
    // 详情
    goDetail (id) {
      this.$router.push({ name: 'marketization-project-add', query: { id: id, showDetail: true } })
    },
    // 修改
    goEdit (id) {
      this.$router.push({ name: 'marketization-project-add', query: { id: id } })
    },
    // 删除
    deleteDataModal (id) {
      this.currentDelId = id
      this.deleteModal = true
    },
    deleteData () {
      deleteForm({ id: this.currentDelId }).then(({ data }) => {
        let { errcode } = data
        if (errcode === 0) {
          this.$Message.success('删除成功!')
          this.currentDelId = ''
          this.getTableData()
        } else {
          this.$Message.warning('删除失败!')
        }
      })
    },
    // 分页查询查找
    getTableData () {
      findPageList(this.pageInfo).then(({ data }) => {
        let { errcode, data: res } = data
        if (errcode === 0) {
          this.tableData = res.results
          this.pageInfo.total = res.totalRecord
        } else {
          this.$Message.warning('获取信息失败!')
        }
      })
    },
    // 分页
    changePage (pageNo) {
      this.pageInfo.pageNo = pageNo
      this.getTableData()
    }
  }
}
</script>

<style scoped lang="less">

</style>
